//用户注册
function register(){
	var userName = $("#userName").val();
	if(!validUserName(userName)){
		ymPrompt.alert({message:'用户名只能为包括：数字、大小写字母、下滑线,且开头只能是字母或下划线的5-16位字符',title:'系统提示',showMask:true,maskAlphaColor:'#ffffff',maskAlpha:'0',width:200,height:140});
		$("#check").html("");
		return;
	}
	var passWord = $("#passWord").val();
	if(validSpace(passWord)||passWord.length<5||passWord.length>16){
		ymPrompt.alert({message:'密码不能包含空格且长度只能为5-16位字符',title:'系统提示',showMask:true,maskAlphaColor:'#ffffff',maskAlpha:'0',width:200,height:140});
		return;
	}
	var rpassWord = $("#rpassWord").val();
	if(rpassWord!=passWord){
		ymPrompt.alert({message:'两次输入的密码不一致',title:'系统提示',showMask:true,maskAlphaColor:'#ffffff',maskAlpha:'0',width:200,height:120});
		return;
	}
	var mail = $("#mail").val();
	if(!validEmail(mail)){
		ymPrompt.alert({message:'邮箱格式不正确',title:'系统提示',showMask:true,maskAlphaColor:'#ffffff',maskAlpha:'0',width:200,height:120});
		return;
	}
	var data = "userName="+userName+"&passWord="+passWord+"&mail="+mail;
	$.ajax({
		type : 'post',
		url : 'registerAction.action',
		data : data,
		dataType : 'json',
		async : false,
		cache : false,
		success : function(data){
		if(data.state=="success"){
		ymPrompt.alert({message:'注册成功',title:'系统提示',showMask:true,maskAlphaColor:'#ffffff',maskAlpha:'0',width:200,height:120});
		}else {
			ymPrompt.alert({message:'注册失败',title:'系统提示',showMask:true,maskAlphaColor:'#ffffff',maskAlpha:'0',width:200,height:120});	
		}
	}
	});
}
//验证用户名是否存在
function checkUserName(){
	var userName = $("#userName").val();
	if(!validUserName(userName)){
	ymPrompt.alert({message:'用户名只能为包括：数字、大小写字母、下滑线,且开头只能是字母或下划线的5-16位字符',title:'系统提示',showMask:true,maskAlphaColor:'#ffffff',maskAlpha:'0',width:200,height:140});
	$("#userName").val("");	
	$("#check").html("");
	return;
	}
	$.ajax({
		type : 'post',
		url : 'checkUserNameAction.action',
		data : "userName="+userName,
		dataType : 'json',
		success : function(data){
		if(data.state=="success"){
			$("#check").html("<font color='green'>可用</font>");
		}else {
			$("#check").html("<font color='red'>不可用</font>");
			$("#userName").val("");	
		}
	}
	});
}
//用户登录
function loginForm(){
	var userName = $("#userName").val();
	if(userName==""){
		//ymPrompt.alert({message:'请输入用户名',title:'系统提示',showMask:true,maskAlphaColor:'#ffffff',maskAlpha:'0',width:200,height:120});
		alert("请输入用户名");
		return;
	}
	var passWord = $("#passWord").val();
	if(passWord==""){
	//	ymPrompt.alert({message:'请输入密码',title:'系统提示',showMask:true,maskAlphaColor:'#ffffff',maskAlpha:'0',width:200,height:120});
		alert("请输入密码");
		return;
	}
	document.form1.submit();
}
